<?php

/**
 * Description of e_phone
 *
 * @author Yefng
 */
namespace c\user;
\lang::load('user');
class e_phone extends \control
{
	var $class = array('PU'=>'\c\auth\permission');
	
    function index_home()
    {
        $this->PU->login();
        if (isset($_POST['new']))
            $this->save();
        $this->loadTemplate('user/edit-phone');
    }
	function save()
	{
		$new = $_POST['new'];
		$s2 = $_POST['s2'];
		$s1 = $_POST['s1'];
		$PO = \YF_f::initC('\c\user\sv_phone');
		
		$this->PU->login();
		$phone = \YF_f::$arr['login_user']['phone'];
		$s = $PO->che($phone, $s1);
		if ($s)
			$this->clue ($s);
		$s = $PO->che($new, $s2);
		if ($s)
			$this->clue ($s);
		
		$b = $this->db->getOne('user', '*',  'phone="'. $this->db->escape($new)  .'"');
		if ($b)
			$this->clue(\lang::g('phone already exist other user'));
		$b = $this->db->save('user', array('phone'=>$new), 'id='.\YF_f::$login_user_id);
		if ($b)
			$this->clue(\lang::g('OK'), '?u=cuser\my');
	}
	//发送2认证
	function index_ss2()
	{
		$phone = $_GET['new'];
		$b = \YF_f::initC('\c\user\sv_phone')->send($phone);
        ajax_json($b? $b: array('status'=>true, 'name'=>str_xx($phone, 6)));
	}
}
